package com.example.dao;

import com.example.domain.ShoppingCart;
import jakarta.servlet.http.PushBuilder;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface ShoppingCartDao {
    @Select("select * from shopping_cart where user_id=#{userId}")
    public List<ShoppingCart> selectall(Long userId);

    @Select("select * from shopping_cart where name=#{name} and user_id=#{userId}")
    public ShoppingCart selectbyname(String name,Long userId);

    @Select("select number from shopping_cart where name=#{name} and user_id=#{userId}")
    public int getnumberbyname(String name,Long userId);

    @Insert("insert into shopping_cart (id,name,image,user_id,setmeal_id,number,amount,create_time) values (#{id},#{name},#{image},#{userId},#{setmealId},#{number},#{amount},#{createTime})")
    public void savethesetmeal(ShoppingCart shoppingCart);

    @Insert("insert into shopping_cart (id,name,image,user_id,dish_id,dish_flavor,number,amount,create_time) values (#{id},#{name},#{image},#{userId},#{dishId},#{dishFlavor},#{number},#{amount},#{createTime})")
    public void savethedish(ShoppingCart shoppingCart);
    @Update("update shopping_cart set number=#{number} where user_id=#{user} and name=#{name}")
    public void updatenumber(int number,Long user,String name);

    @Select("select * from shopping_cart where setmeal_id=#{id} and user_id=#{user} ")
    public ShoppingCart getnumberbysetmeal(Long id,Long user);

    @Delete("delete from shopping_cart where name=#{name} and user_id=#{userId}")
    public void deletebyname(String name,Long userId);

    @Select("select * from shopping_cart where dish_id=#{dishId} and user_id=#{userId}")
    public ShoppingCart getnumberbydish(Long dishId,Long userId);

    @Delete("delete from shopping_cart where user_id=#{userId}")
    public void clean(Long userId);
}
